package com.pay.dubbo.outer.impl;

import com.pay.bean.QuickPayTradeContext;
import com.pay.bean.ResponseBean;
import com.pay.bean.QuickPayTradeBean;
import com.pay.entity.trans.BankInterface;
import com.pay.entity.trans.PayReuquest;
import com.pay.handler.QuickPayHandler;
import com.pay.service.QuickPayTransFacadeService;
import com.pay.service.impl.TransRouteManager;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * decs:
 * Created by @hsk198
 * 2017/9/24 0024
 */
@Service("quickPayTransFacadeService")
public class QuickPayTransFacadeServiceImpl implements QuickPayTransFacadeService {

    @Resource
    private Map<String,QuickPayHandler> quickPayHandlerMap;

    @Resource
    private TransRouteManager transRouteManager;//路由及规则封装

    @Override
    public ResponseBean<String> quickPayTrans(QuickPayTradeBean tradeBean) {
        //是否绑结算卡
        String customerNo = tradeBean.getCustomerNo();
        //tranCard是否存在
        String encrypTradeCardId = tradeBean.getTradeCardToken();

        //payOrder\payRequest
        QuickPayTradeContext tradeContext = new QuickPayTradeContext();
        BankInterface bankInterface = transRouteManager.getRoute(tradeContext);//获取交易通道
        QuickPayHandler quickPayHandler = quickPayHandlerMap.get(bankInterface.getBankInterfaceCode());//获取处理handler
        Object[] result = quickPayHandler.trade(tradeContext);//交易
        //完成
        Map<String,Object> map = new HashMap<String,Object>();
        PayReuquest complete = quickPayHandler.complete(map);//完成交易
        return null;
    }
}
